<template>
    <el-dialog v-model="props.visible" width="40%" @close="handleClose">
        <template #header>
            <div class="header">
                <h3>销售审核</h3>
                <el-icon class="tips-icon">
                    <QuestionFilled />
                </el-icon>
                <span class="tips">此付款单号已用于销售单审核，合同销售审核，请核对后再试</span>
            </div>
        </template>
        <el-card shadow="never">
            <template #header>
                <el-form>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="客户名称">
                                <span class="contract-info">{{ props.data?.customerName }}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="应收金额">
                                <span class="contract-info">{{ props.data?.contractDeposit }}</span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-form-item label="已收金额">
                        <span class="contract-info">{{ props.data?.depositAlreadyPaid || 0 }}</span>
                    </el-form-item>
                </el-form>
            </template>
            <el-form :model="formData" ref="formRef" label-positio="left">
                <el-row :gutter="30">
                    <el-col :span="12">
                        <el-form-item label="付款方式" prop="payMethod" >
                            <el-select v-model="formData.paymentMethod" placeholder="请选择" default-first-option :style="{width:'100%'}">
                                <el-option label="线上付款" value="1"></el-option>
                                <el-option label="线下付款" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                
                <el-row :gutter="30">
                    <el-col :span="12">
                        <el-form-item label="收款账号" prop="cardNumber" v-if="formData.paymentMethod == '2'">
                            <el-select v-model="formData.cardNumber" :style="{width:'100%'}">
                                <el-option v-for="item in props.account" :label="item.label" :value="item.label"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="店铺名称" prop="shopName" v-if="formData.paymentMethod == '1'">
                            <el-select v-model="formData.shopName" :style="{width:'100%'}">
                                <el-option v-for="item in props.store" :label="item.label" :value="item.label"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="付款日期" prop="paymentDate" >
                            <el-date-picker type="date" v-model="formData.paymentDate" placeholder="付款时间"  format="YYYY-MM-DD" value-format="YYYY-MM-DD" :style="{width:'100%'}" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="30">
                    <el-col :span="12">
                        <el-form-item label="付款金额" prop="paymentAmount">
                            <el-input placeholder="请输入" v-model.number="formData.paymentAmount"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item :label="formData.paymentMethod == '2'?'付款人':'付款单号'" prop="paymentAccount">
                            <el-input :placeholder="formData.paymentMethod == '2'?'请输入付款人姓名':'请输入付款单号'" v-model="formData.paymentAccount"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item label="收款备注" prop="remark">
                    <el-input type="textarea" maxlength="128" show-word-limit placeholder="请输入" v-model="formData.remark"></el-input>
                </el-form-item>
            </el-form>
            
        </el-card>
        <template #footer>
            <div class="dialog-footer">
                <el-button  type="primary" @click="handleSubmit">确 定</el-button>
                <el-button @click="handleClose">取 消</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance } from 'element-plus';
import { examineContractDetailsApi } from '@/api/sj/contract-crm/index';

const props = defineProps(['visible','data','account','store']);
const emits = defineEmits(['close','submit']);
const formRef = ref<FormInstance>();
const formData = ref({
    paymentMethod: '1',
    shopName: undefined,
    cardNumber: undefined,
    paymentDate: undefined,
    paymentAmount: undefined,
    paymentAccount: undefined,
    remark: undefined
});

const handleSubmit = async () => {
    const submitData = {...formData.value, contractId: props.data.id};
    console.log(submitData);
    await examineContractDetailsApi(submitData).then((result)=>{
        if(result.code == 200){
            emits('submit',true);
            handleClose();
        }else{
            emits('submit',false);
        }
    });
};

const handleClose = ()=>{
    formRef.value?.resetFields();
    emits('close');
};

</script>

<style scoped>
.header{
    display: flex;
    align-items: center;
    .el-icon{
        margin-left:10px;
    };
    .tips-icon:hover + .tips{
        visibility: visible;
    }
    .tips{
        color: red;
        font-size: 15px;
        margin-left: 25px;
        visibility: hidden;
    }
}
.contract-info{
    font-weight: bolder;
}

::v-deep(.el-input__wrapper){
    width:100%
}

.dialog-footer{
    display:flex;
    justify-content: center;
}
</style>